package extra01GUI;

import java.awt.FlowLayout;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class VCirculo extends JDialog implements ActionListener {
	
	private JLabel lblRadio;
	private JTextField txtRadio;
	private JButton btnInfo;
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	public VCirculo(JFrame F){
		super(F,"Circulo");
		
		lblRadio = new JLabel("Radio del Circulo:");
		txtRadio = new JTextField(20);
		btnInfo = new JButton("Informacion");
		btnInfo.addActionListener(this);
		
		FlowLayout fl = new FlowLayout(FlowLayout.RIGHT);
		JPanel p1 = new JPanel(fl);
		p1.add(lblRadio);
		p1.add(txtRadio);
		JPanel p2 = new JPanel(fl);
		p2.add(btnInfo);
		
		setLayout(new BoxLayout(getContentPane(), BoxLayout.PAGE_AXIS));
		add(p1);
		add(p2);
		
		setModal(true);
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);	
		Point punto = F.getLocation();
		setLocation(punto.x, punto.y);
	}
	
	public void Iniciar(){
		pack();
		setResizable(false);
		setVisible(true);
	}

	public void actionPerformed(ActionEvent arg0) {
		double tmp = 0;
		boolean estado = true;
		
		try{			
			tmp = Double.parseDouble(txtRadio.getText()); 
		}catch (NumberFormatException e){
			estado = false;
		}
		
		if(estado){			
			String dato = UtilidadGeometria.Circulo(tmp);
			JOptionPane.showMessageDialog(this, dato, "Resultado", JOptionPane.INFORMATION_MESSAGE);
		}else{
			JOptionPane.showMessageDialog(this, "Error en el ingreso de datos", "Informacion", JOptionPane.ERROR_MESSAGE);
		}
	}

}
